layui.define(['layer', 'form'], function (exports) {
    var $ = layui.$
        , layer = layui.layer
        , admin = layui.admin
        , form = layui.form
        ,view = layui.view;;

    var userId;

    document.onkeydown = function (e) { // 回车提交表单
        // 兼容FF和IE和Opera
        var theEvent = window.event || e;
        var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
        if (code == 13) {
            $('#submitBut').click();
        }
    }

    //确认修改
    form.on('submit(setmypass)', function (obj) {
        // 请求公钥
        admin.req({
            url: layui.setter.ctx + '/system/sysUser/updatePassword'
            , type: 'put'
            , data: obj.field
            , done: function (res) {
                layer.msg("修改成功，5秒后将退出登录", {
                    icon:5,
                    time: 5000,
                    shade: 0.6,
                    success: function (layero, index) {
                        var msg = layero.text();
                        var i = 5;
                        var timer = null;
                        var fn = function () {
                            layero.find(".layui-layer-content").html('<i class="layui-layer-ico layui-layer-ico1"></i>' + msg + '(' + i + ')');

                            if (!i) {
                                layer.close(index);
                                clearInterval(timer);
                            }
                            i--;
                        };
                        timer = setInterval(fn, 1000);
                        fn();
                    },
                }, function () {
                    view.exit();
                });
            }
        });
    });

    //对外暴露的接口
    exports('password', {});
});